package com.vichat.common.util;

import com.vichat.common.signal.SignalCmdUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

import java.util.Random;


@Component
public class SignalClientInit implements ApplicationContextAware {

    private static transient Logger logger = LoggerFactory.getLogger(SignalClientInit.class);

    public void setApplicationContext(ApplicationContext ctx) throws BeansException {
        try {
            boolean flag = true;
            while (flag) {
                int port = new Random().nextInt(20000);
                if (port < 1000) continue;
                SignalCmdUtil.init(port);
                flag = false;
            }
        } catch (Exception e) {
            logger.error("RUDP初始化失败", e);
        }
    }

}
